package com.bodgittandscarper.broker.types.impl;

import java.util.ArrayList;
import java.util.List;

import com.bodgittandscarper.broker.types.DatabaseField;
import com.bodgittandscarper.broker.types.DatabaseSchema;
import com.bodgittandscarper.broker.types.DatabaseSchemaMod;

/**
 * Implementation class of the {@link com.bodgittandscarper.broker.types.DatabaseSchema} 
 *
 * @author Morten Rummelhoff
 *
 */
public class DatabaseSchemeImpl implements DatabaseSchemaMod{

	/**
	 * Version number for serializable object.  
	 */
	private static final long serialVersionUID = -2424743039056044538L;
	
	private List<DatabaseField> databaseFieldList;
	
	/**
	 * Constructor that initializes an empty {@link DatabaseSchema} holding no {@link DatabaseField}.
	 */
	public DatabaseSchemeImpl() {
		databaseFieldList = new ArrayList<DatabaseField>();
	}

	public void addDatabaseField(DatabaseField databaseField) {
		databaseFieldList.add(databaseField);
	}

	public DatabaseField getDatabaseField(int index) {
		if (databaseFieldList != null)
			return databaseFieldList.get(index);
		
		return null; 
	}
	
	public int getDatabaseFieldCount() {
		return databaseFieldList.size();
	}
	
	@Override
	public String toString() {		
		StringBuffer result = new StringBuffer("DatabaseFieldList: \n");
		
		for (DatabaseField databaseField : databaseFieldList) {
			result.append(databaseField.toString() + "\n");
		}
		
		return result.toString();
	}
	
}
